﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.ApllicationDto;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;
using Zocono.WMS.Infrastructure.BaseRepository;

namespace Zocono.WCS.Infrastructure.Repository
{
    public class DispatchEquipmentRepository : BaseRepository<DispatchEquipmentInfo>, IDispatchEquipmentRepository
    {
        public DispatchEquipmentRepository(SqlSugarClient context = null) : base(context)
        {

        }

        public async Task<PageDto<DispatchEquipmentInfoDto>> GetDispatchEquipmentAsync(Expression<Func<DispatchEquipmentInfo, EquipmentTypeInfo, bool>> exp, PageModel page)
        {
            PageDto<DispatchEquipmentInfoDto> pageDto = new PageDto<DispatchEquipmentInfoDto>();
            RefAsync<int> totalNumber = 0;
            var result = await Context.Queryable<DispatchEquipmentInfo, EquipmentTypeInfo>((a, b) => new JoinQueryInfos(
                JoinType.Inner, a.EquipmentTypeID == b.ID))
                .Where(exp)
                .Select((a, b) => new DispatchEquipmentInfoDto
                {
                    ID = a.ID,
                    AreaCode = a.AreaCode,
                    EquipmentCode = a.EquipmentCode,
                    EquipmentName = a.EquipmentName,
                    EquipmentTypeID = a.EquipmentTypeID,
                    StationCount = a.StationCount,
                    EquipmentTypeName = b.TypeName
                }).ToPageListAsync(page.PageIndex, page.PageSize, totalNumber);
            pageDto.Result = result;
            pageDto.Total = totalNumber;
            return pageDto;
        }
    }

}
